package com.hb.unic.core.async.threadpool;

import java.util.concurrent.ThreadPoolExecutor;

import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * IO密集型 - 线程池操作类
 *
 * @since v1.0，2023/8/27 12:59，create by Mr.Huang.
 */
@Configuration
@ConditionalOnExpression("${config.threadpool.ioTaskExecutor:false}")
public class IoThreadPoolTaskOperation extends BaseThreadPoolOperation {

    @Bean
    protected ThreadPoolExecutor ioTaskExecutor() {
        int availableProcessors = Runtime.getRuntime().availableProcessors();
        int corePoolSize = availableProcessors * 2;
        int maxPoolSize = corePoolSize * 2;
        return createExecutor(corePoolSize, maxPoolSize, 60, 500, "ioTaskExecutor-",
            new ThreadPoolExecutor.AbortPolicy());
    }

}
